from __future__ import with_statement
from sikuli.Sikuli import *

class SikuliLibrary(object):
	def __init__(self):
		self.appCoordinates = (0, 0, 1024, 768)
		
	#start application by choosing the path to application
	def startApp(self,pathApp):
		#addImagePath(pathToImageFolder)
		calcApp = App("Calculator")
		print calcApp.window()
		if not calcApp.window():
			App.open(pathApp); wait(3)
		calcApp.focus(); wait(5)
		
	#click on image region
	def click(self,pathToImage):
		Screen(0).click(pathToImage)
		
	def doubleClick(seft, pathToImage):
		Screen(0).doubleClick(pathToImage)
	
	#right click
	def rightClick(seft,pathToImage):
		Screen(0).rightClick(pathToImage)
	
	#type a text 
	def type(seft,string):
		type(string)
	
	#type a text 
	def typeAndPress(seft,string):
		type(string + Key.ENTER)
		
	#type a text at a location
	def typeAtLocation(seft,pathToImage,string):
		type(pathToImage,string)
	
	#paste a text 
	def paste(seft,string):
		paste(string)
		
	#match a location then paste a string
	def pasteAtLocation(seft,pathToImage,string):
		paste(pathToImage,string)
		
	#move the mouse cursor on the best matched GUI component.
	def hover(seft,pathToImage):
		hover(pathToImage)
		
	#find a location
	def find(seft,pathToImage):
		find(pathToImage)
	
	#looks for all the best matched GUI component or in the Region
	def findAll(seft,pathToImage):
		findAll(pathToImage)
		
	#waits the given GUI component to appear on the Screen or in the Region for up to timeout seconds
	def wait(seft,pathToImage):
		wait(pathToImage)
		
	#waits the given GUI component to disappear on the Screen or in the Region for up to timeout seconds
	def waitVanish(seft,pathToImage,timeOut):
		waitVanish(pathToImage,timeOut)
		
	#check if the given GUI component exist on the screen or in the region. If it is not found, None will be return without throwing an exception
	def exists(seft,pathToImage):
		rs = exists(pathToImage)
		if rs != "None":
			return 1
		else:
			return 0
		#return exists(pathToImage)
		
	#high light the region for some period of time
	def highLight(seft,pathToImage,timeOut):
		image=find(pathToImage)
		for i in range(1):
			image.highlight(1)
			wait(timeOut)
	#drag the first component, and drop at the second component
	def dragDrop(seft,pathToFirstImage,pathToSecondImage):
		dragDrop(pathToFirstImage,pathToSecondImage)